function PromptError(a) {
    wx.showToast({
        title: a,
        image: '/images/!.png',
        duration: 1500,
        mask: true,
    })
}//提示错误
function Success(b, d) {
    wx.showToast({
        title: b,
        icon: 'success',
        duration: 1500,
        mask: true,
        success: function () {
            d && d();
        }
    })
}//提示成功回调
function showLoading(c) {
    wx.showLoading({
        mask: true,
        title: c,
    })
}//加载中
function showModal(ft, tit, con, confirm, cancel) {
    wx.showModal({
        title: tit,
        content: con,
        showCancel: ft,
        confirmText: '确定',
        confirmColor: '#f75019',
        success: function (res) {
            if (res.confirm) {
                confirm && confirm()
            } else if (res.cancel) {
                cancel && cancel();
            }
        }
    })
}//弹出确定取消
//倒计时函数
function timeFormat(param) {
    return param < 10 ? '0' + param : param;
}
function countDown({ timeEnd: timeEnd, that: that, treamName: treamName, succ: succ}) {
    let i = 0;
    that[treamName] = setInterval( ()=> {
        // 获取当前时间，同时得到活动结束时间数组
        let newTime = parseInt(new Date() / 1000);
        let endTimeList = timeEnd;
        let countDownArr = [];
        // 对结束时间进行处理渲染到页面
        endTimeList.forEach(o => {
            let endTime = o;
            let obj = null;
            // 如果活动未结束，对时间进行处理
            if (endTime - newTime > 0) {
                let time = endTime - newTime;
                // 获取天、时、分、秒
                let day = parseInt(time / (60 * 60 * 24));
                let hou = parseInt(time % (60 * 60 * 24) / 3600);
                let min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
                let sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);
                obj = {
                    day: timeFormat(day),
                    hou: timeFormat(hou),
                    min: timeFormat(min),
                    sec: timeFormat(sec)
                }
            } else {//活动已结束，全部设置为'00'
                i++;
                obj = {
                    day: '00',
                    hou: '00',
                    min: '00',
                    sec: '00'
                }
            }
            countDownArr.push(obj);
        })
        // 渲染，然后每隔一秒执行一次倒计时函数
        // succ && succ(countDownArr);
        if (i == endTimeList.length) {
            succ && succ(countDownArr);
            clearInterval(that[treamName]);
        }
        that.setData({ [treamName]: countDownArr });
    }, 1000);
}
function getUrlCode(e) {
    let paramsArr = e.match(/\?\S+/)[0].replace('?', '').split('&');
    let params = {};
    for (let i = 0; i < paramsArr.length; i++) {
        let tmp = paramsArr[i].split('=');
        params[tmp[0]] = tmp[1];
    }
    return params;
}
module.exports = {
    PromptError: PromptError,
    Success: Success,
    showLoading: showLoading,
    showModal: showModal,
    countDown: countDown,
    getUrlCode: getUrlCode
}
